package com.sfddata.musicpillow.user.service.impl;

import com.sfddata.musicpillow.user.controller.QuestionInfoController;
import com.sfddata.musicpillow.user.entity.QuestionImgEntity;
import com.sfddata.musicpillow.user.service.QuestionImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sfddata.musicpillow.common.utils.PageUtils;
import com.sfddata.musicpillow.common.utils.Query;

import com.sfddata.musicpillow.user.dao.QuestionInfoDao;
import com.sfddata.musicpillow.user.entity.QuestionInfoEntity;
import com.sfddata.musicpillow.user.service.QuestionInfoService;


@Service("questionInfoService")
public class QuestionInfoServiceImpl extends ServiceImpl<QuestionInfoDao, QuestionInfoEntity> implements QuestionInfoService {

    @Autowired
    private QuestionImgService questionImgService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<QuestionInfoEntity> page = this.page(
                new Query<QuestionInfoEntity>().getPage(params),
                new QueryWrapper<QuestionInfoEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void addQAF(QuestionInfoEntity entity, List<String> fileList) {

        int insert = baseMapper.insert(entity);
        for (String url : fileList) {
            QuestionImgEntity questionImgEntity = new QuestionImgEntity();
            questionImgEntity.setQuestionId(entity.getId());
            questionImgEntity.setImgUrl(url);
            questionImgService.save(questionImgEntity);
        }
    }

}